package com.bestcem.xm.ticket.service.impl;

import com.bestcem.xm.ticket.dao.TicketRecordDao;
import com.bestcem.xm.ticket.entity.mongo.Ticket;
import com.bestcem.xm.ticket.entity.mongo.TicketRecord;
import com.bestcem.xm.ticket.enums.TicketRecordEventEnum;
import com.bestcem.xm.ticket.enums.TicketRecordSourceEnum;
import com.bestcem.xm.ticket.service.TicketRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * TicketRecordServiceImpl记录工单的各个进度
 * * 一个工单对应多条记录
 *
 * @author jy.zhao
 * @version 1.0
 * @date 2021/8/24 14:02
 **/
@Service
@Slf4j
public class TicketRecordServiceImpl implements TicketRecordService {

    @Resource
    private TicketRecordDao ticketRecordDao;

    @Override
    public TicketRecord createTicketRecord(Ticket ticket, TicketRecordEventEnum recordStatus) {
        TicketRecord ticketRecord = new TicketRecord();
        ticketRecord.setOrgId(ticket.getOrgId());
        ticketRecord.setTicketId(ticket.getId());
        ticketRecord.setEvent(recordStatus.getIndex());
        ticketRecord.setTitle(recordStatus.getName());
        ticketRecord.setSource(TicketRecordSourceEnum.SYSTEM.getIndex());
        ticketRecord.setRegionName("");
        ticketRecord.setUserName("系统");
        ticketRecord.setSurveyId(ticket.getSurveyId());
        // 2.3 TicketRecord 新增当前工单状态记录
        ticketRecord.setTicketStatus(ticket.getStatus());
        return ticketRecordDao.saveTicketRecord(ticketRecord);
    }
}
